﻿using Furion.DatabaseAccessor;
using Furion.DataEncryption;
using Furion.DependencyInjection;
using Furion.FriendlyException;
using HOPU.OnlineSchool.Application.Users.Dtos;
using HOPU.OnlineSchool.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HOPU.OnlineSchool.Application.Users.Services
{
    public class UserService : IUserService, ITransient
    {
        private readonly IRepository<AclUser> _repository;
        public UserService(IRepository<AclUser> repository)
        {
            _repository = repository;
        }
        public async Task<LoginInfoOutput> LoginAsync(LoginInfoInput input)
        {

            var password = MD5Encryption.Encrypt(input.Password);
            var model= await _repository.FirstOrDefaultAsync(e => e.Username == input.UserName && e.Password == password);
            if (model == null) throw Oops.Oh("用户名或密码有误");

            //返回token（临时处理，后续优化）
            return new LoginInfoOutput() { Token = "admin" };
        }
    }
}
